package org.mili.ticketeer.service;

import org.mili.ticketeer.dao.ActionDao;
import org.mili.ticketeer.dao.DaoFactory;
import org.mili.ticketeer.dao.ModificationResult;
import org.mili.ticketeer.dto.Action;
import org.mili.ticketeer.dto.Contact;
import org.mili.ticketeer.dto.Ticket;
import org.mili.ticketeer.util.Lambda;

import java.util.List;

public class ActionService extends Service {
	private ActionDao _actionDao = DaoFactory.getDao(ActionDao.class);

    public ModificationResult write(final Action action) throws ServiceException {
        return doInService(new Lambda<ModificationResult>() {
            @Override
            public ModificationResult exec(Object... params) throws Exception {
                return _actionDao.write(action);
            }
        });
    }

    public ModificationResult delete(final Action action) throws ServiceException {
        return doInService(new Lambda<ModificationResult>() {
            @Override
            public ModificationResult exec(Object... params) throws Exception {
                return _actionDao.delete(action);
            }
        });
    }

    public Boolean assign(final Contact contact, final Action action) throws ServiceException {
        return doInService(new Lambda<Boolean>() {
            @Override
            public Boolean exec(Object... params) throws Exception {
                return _actionDao.assign(contact, action);
            }
        });
    }

    public List<Action> getActionsFor(final Ticket ticket) throws ServiceException {
        return doReadInService(new Lambda<List<Action>>() {
            @Override
            public List<Action> exec(Object... params) throws Exception {
                return _actionDao.getActionsFor(ticket);
            }
        });
    }

    public List<Contact> getAssignmentsFor(final Action action) throws ServiceException {
        return doReadInService(new Lambda<List<Contact>>() {
            @Override
            public List<Contact> exec(Object... params) throws Exception {
                return _actionDao.getAssignmentsFor(action);
            }
        });
    }
}
